package com.coffee.minio.args;

import io.minio.PutObjectArgs;
import lombok.*;
import lombok.experimental.Accessors;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

/**
 * @author: songkui
 * @since: 2023/5/10
 */
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@Builder
public class MochaPutObjectArgs extends MochaBaseArgs {

    private InputStream stream;

    private String fileName;
    private String creator;

    public PutObjectArgs buildMinioArgs() throws IOException {
        Map<String, String> userMetadata = new HashMap<>(mapSize(2));
        userMetadata.put("File-Name", this.fileName);
        userMetadata.put("Creator", this.creator);

        return PutObjectArgs.builder()
                .bucket(this.getBucket())
                .object(this.getObject())
                .stream(stream, stream.available(), -1) //目前附件比较小 可以这样传入
                .userMetadata(userMetadata)
                .build();

    }

}
